<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/common/commonConfig.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>
    <base href="<%=basePath%>">
    <title>工作站列表</title>
    <script src="<%=basePath%>component/layout.js"></script>
    <script src="<%=basePath%>component/toolbar.js"></script>
	<script src="<%=basePath%>component/grid.js"></script>
	<script type="text/javascript" src="<%=basePath%>dwrsystem/engine.js"></script>
	<script type="text/javascript" src="<%=basePath%>dwrsystem/interface/worksiteService.js"></script>
	<script type="text/javascript">
var dhxLayout = createLayoutNormal('1C');
var mygrid;
function configLayout(){
	var a = dhxLayout.cells('a');
	a.hideHeader();
	a.setText('主页面');
	a.fixSize(true, true);
	mygrid = createGridFromLayoutCell(a);
	//validate power of operation
	if(power.getPower() != '' && (power.getPowerInsert() || power.getPowerDelete()))
		createToolbarFromDHXLayoutCell(a,function(toolbar){
		    toolbar.addText("info", 1, "操作:");
		    toolbar.addSeparator("sep1", 2);
		    if(power.getPowerInsert())toolbar.addButton("add", 3, "新增", "new.gif", "new_dis.gif");
		    if(power.getPowerDelete())toolbar.addButton("delete", 4, "删除", "cut.gif", "cut_dis.gif");
		    //if(power.getPowerUpdate())toolbar.addButton("update", 5, "修改", "settings.gif", "settings.gif");
		    toolbar.attachEvent("onClick", function(id) {
		    	if(id == 'add'){
		    		dhxGrid.createInfo();
		    	}
		    	if(id == 'delete'){
		    		dhxGrid.deleteInfo();
		    	}
		    });
		});
}
var dhxGrid = {
	initDataTable : function () {
	    mygrid.setHeader("序号,工作站名称,工作站地址,备注");
	    mygrid.setInitWidths("50,200,200,*");
	    mygrid.setColAlign("right,left,left,left");
	    mygrid.setColSorting("int,str,str,str");
	    //validate update power
	    mygrid.setColTypes(power.getPowerUpdate()?"ro,ed,ed,ed":"ro,ro,ro,ro");
	    mygrid.attachEvent("onEditCell", this.onEditCell);
	    mygrid.init();
	    setSkin(mygrid);
	    mygrid.loadXML('<%=basePath%>system-worksite/WorksiteAction!worksiteGrid.action',function(){
mygrid.setColLabel(1,'工作站名称<input name="gridFilter" id="wnameFilter_1" type="text" style="width: 100px; border:1px solid gray;" onClick="(arguments[0]||window.event).cancelBubble=true;" onKeyUp="filterBy(mygrid)" ></input>');
mygrid.setColLabel(2,'工作站地址<select name="gridFilter" id="ipFilter_2" style="width:100px;" onclick="(arguments[0]||window.event).cancelBubble=true;" onChange="filterBy(mygrid)"></select>');
//mygrid.attachHeader("#rspan,<div id='title_flt' style='padding-right:3px'></div>,<div id='author_flt' style='padding-right:3px'></div>,#rspan");
	        populateSelectCell("ipFilter_2",mygrid);
	    });
	},
	onEditCell : function (stage,rId,cInd,nValue,oValue){
		if(stage == 2 && nValue != oValue){
			if(cInd == '1'){
				layoutProgressOn(dhxLayout);
				worksiteService.updateTWorksite({worksiteId:rId,siteName:nValue},function(data){
					parent.notifyCreater("工作站名称修改成功");layoutProgressOff(dhxLayout);
				});
			}
			if(cInd == '2'){
				layoutProgressOn(dhxLayout);
				worksiteService.updateTWorksite({worksiteId:rId,siteIp:nValue},function(data){
					parent.notifyCreater("工作站地址修改成功");
					populateSelectCell("ipFilter_2",mygrid);
					layoutProgressOff(dhxLayout);
				});
			}
			if(cInd == '3'){
				layoutProgressOn(dhxLayout);
				worksiteService.updateTWorksite({worksiteId:rId,note:nValue},function(data){
					parent.notifyCreater("工作站备注修改成功");layoutProgressOff(dhxLayout);
				});
			}
	   	}
	    return true;
	},
	createInfo : function (){
		layoutProgressOn(dhxLayout);
		worksiteService.insertByTWorksite({worksiteId:''},function(data){
			mygrid.addRow(data, ''+(mygrid.getRowsNum()+1), ''+mygrid.getRowsNum());
			mygrid.selectRowById(data);
			parent.notifyCreater("工作站创建成功");layoutProgressOff(dhxLayout);
		});
	},
	deleteInfo : function (){
		if(mygrid.getSelectedId()){
			confirmInfo('确认删除？',
				function(choose){
					if('ok' == choose){
						layoutProgressOn(dhxLayout);
						worksiteService.deleteTWorksiteByPK({worksiteId:mygrid.getSelectedId()},function(data){
							var lastrowIndex = mygrid.getRowIndex(mygrid.getSelectedId())-1;
							mygrid.deleteSelectedRows();
							mygrid.selectRow(lastrowIndex);
							
							for(var i=(lastrowIndex+1) ;i<(mygrid.getRowsNum());i++){
								mygrid.cells(mygrid.getRowId(''+i),0).setValue(i+1);
							}
							parent.notifyCreater('删除成功');
							layoutProgressOff(dhxLayout);
						});
					}else{
						layoutProgressOff(dhxLayout);
						return;
					}
				}
			);
		}else {
			parent.notifyWarn('请先选择一条记录');
		}
	}
};

$(function (){
	configLayout();
 	dhxGrid.initDataTable();
});
	</script>
</head>  
<body>
</body>
</html>